<?php

namespace App\Http\Controllers\Api;

use App\Models\ClassCard;
use Doctrine\DBAL\Exception\DatabaseObjectExistsException;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class ClassCardController extends ApiController
{
    private $uid = '';


    public function __construct(Request $request)
    {
        $this->uid = auth('api')->id();
    }
    //个人报名情况
    public function getCardByUid(){
        $res = ClassCard::getCardById($this->uid);
        $res = $res ?? '';
        return self::returnAjax($res, 200, "个人报名情况");
    }

    //我所在球队的课程以及具体课时列表
    public function getDetailHour(Request $request){
         $team_id = $request['id'];
//         $uid =  $this->uid;
//         $team_id = DB::table('user')->where('id',$uid)->value('team_id');

           $res =  DB::table('course')
                 ->where('team_id',$team_id)
                 ->select('class_name','class_start_time', 'class_end_time','id')
                 ->orderBy('id','asc')
                 ->get();
           foreach ($res as $k=>&$v){
                 $v->class_start_time = date('Y-m-d H:i:s',$v->class_start_time);
                 $v->class_end_time = date('Y-m-d H:i:s',$v->class_end_time);
           }
             return self::returnAjax(['list'=>$res], 200, "success");
    }


}
